package com.jacobson.core.framework.configuration

import android.app.Application
import com.google.gson.GsonBuilder

/**
 * ================================================
 * Gson配置类
 * @author Wucz on 2018/7/18 20:07
 * ================================================
 */
class GsonConfiguration internal constructor(buidler: Builder) {
    var onBuildInterceptor: OnBuildInterceptor? = null

    init {
        buidler.let {
            onBuildInterceptor = it.onBuildInterceptor
        }
    }

    class Builder internal constructor(init: Builder.() -> Unit) {
        internal var onBuildInterceptor: OnBuildInterceptor? = null

        init {
            init()
        }

        fun onBuildInterceptor(closure: () -> OnBuildInterceptor): Builder {
            this.onBuildInterceptor = closure()
            return this
        }

        fun build(): GsonConfiguration {
            return GsonConfiguration(this)
        }
    }

    interface OnBuildInterceptor {
        fun onBuildIntercept(application: Application, builder: GsonBuilder)
    }

    companion object {
        fun build(init: Builder.() -> Unit): GsonConfiguration = Builder(init).build()
    }
}